//Copyright (c) 2012 Tim Shannon
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in
//all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//THE SOFTWARE.

package bullet

//#cgo pkg-config: bullet
//#include <bullet/Bullet-C-Api.h>
//#include <stdlib.h>
//#include "callback.h"
import "C"
import "unsafe"

type DynamicsWorld struct{ handle C.plDynamicsWorldHandle }
type RigidBody struct{ handle C.plRigidBodyHandle }
type CollisionShape struct{ handle C.plCollisionShapeHandle }
type Constraint struct{ handle C.plConstraintHandle }
type MeshInterface struct{ handle C.plMeshInterfaceHandle }

type BroadphaseProxy struct{ handle C.plBroadphaseProxyHandle }
type CollisionWorld struct{ handle C.plCollisionWorldHandle }

type PhysicsSdk struct{ handle C.plPhysicsSdkHandle }

func NewBulletSdk() *PhysicsSdk {
	return &PhysicsSdk{C.plNewBulletSdk()}
}

func (p *PhysicsSdk) Delete() {
	C.plDeletePhysicsSdk(p.handle)
}

type BroadphaseCallback func(clientData *interface{}, object1, object2 *RigidBody)
type CollisionBroadphase struct{ handle C.plCollisionBroadphaseHandle }

//global callback variables
var beginCB BroadphaseCallback
var endCB BroadphaseCallback

func CreateSapBroadphase(beginCallback, endCallback BroadphaseCallback) *CollisionBroadphase {

}

//export goBeginBroadphaseCallback
func goBeginBroadphaseCallback(clientData, object1, object2 unsafe.Pointer) {
	beginCB((*interface{})(clientData), object1, object2)
}

//export goEndBroadphaseCallback
func goEndBroadphaseCallback(clientData, object1, object2 unsafe.Pointer) {

}

//func (b *CollisionBroadphase) Destroy() {
//	C.plDestroyBroadphase(b.handle)
//}
